/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.elec.bulk.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.elec.bulk.entity.ElecConvenientBulk;
import cn.net.ecode.elec.bulk.service.ElecConvenientBulkService;

/**
 * 便利团Controller
 * @author AlanShelby
 * @version 2019-09-26
 */
@Controller
@RequestMapping(value = "${adminPath}/bulk/elecConvenientBulk")
public class ElecConvenientBulkController extends BaseController {

	@Autowired
	private ElecConvenientBulkService elecConvenientBulkService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElecConvenientBulk get(String id, boolean isNewRecord) {
		return elecConvenientBulkService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("bulk:elecConvenientBulk:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElecConvenientBulk elecConvenientBulk, Model model) {
		model.addAttribute("elecConvenientBulk", elecConvenientBulk);
		return "elec/bulk/elecConvenientBulkList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("bulk:elecConvenientBulk:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<ElecConvenientBulk> listData(ElecConvenientBulk elecConvenientBulk, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ElecConvenientBulk> page = elecConvenientBulkService.findPage(new Page<ElecConvenientBulk>(request, response), elecConvenientBulk); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("bulk:elecConvenientBulk:view")
	@RequestMapping(value = "form")
	public String form(ElecConvenientBulk elecConvenientBulk, Model model) {
		model.addAttribute("elecConvenientBulk", elecConvenientBulk);
		return "elec/bulk/elecConvenientBulkForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("bulk:elecConvenientBulk:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(ElecConvenientBulk elecConvenientBulk) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, elecConvenientBulk)){
			return renderResult(Global.FALSE, message);
		}
		elecConvenientBulkService.save(elecConvenientBulk);
		return renderResult(Global.TRUE, "保存便利团成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("bulk:elecConvenientBulk:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(ElecConvenientBulk elecConvenientBulk) {
		elecConvenientBulkService.delete(elecConvenientBulk);
		return renderResult(Global.TRUE, "删除便利团成功！");
	}

}